package repman.test;

import java.io.File;
import java.io.IOException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

public class testxml {

	/**
	 * @param args
	 * @throws IOException 
	 * @throws SAXException 
	 * @throws XPathExpressionException 
	 */
	public static void main(String[] args) throws SAXException, IOException, XPathExpressionException {
		// TODO Auto-generated method stub
	/*
		File f = new File("d:\\WORK\\repman\\reports.xml");
		DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
		DocumentBuilder dBuilder = null;
		try {
			dBuilder = dbFactory.newDocumentBuilder();
		} catch (ParserConfigurationException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		Document doc = dBuilder.parse(f);
		XPath xPath =  XPathFactory.newInstance().newXPath();
		Node dir = doc.getElementsByTagName("directory").item(0);
		
		dir = (Node) xPath.compile("/reports/directory").evaluate(doc, XPathConstants.NODE);
				
		String expression = "/reports/directory/group[@name='group2']";
		expression = "./group[@name='group2']";
		NodeList  children = null;
//		children = (NodeList) xPath.compile(expression).evaluate(dir, XPathConstants.NODESET);
//		children = (NodeList) xPath.compile("group | report").evaluate(children.item(0), XPathConstants.NODESET);
		children = (NodeList) xPath.compile("/reports/description/report[@name='dodo2']").evaluate(doc, XPathConstants.NODESET);
		Node rep = (Node) xPath.compile("/reports/description/report[@name='dodo2']").evaluate(doc, XPathConstants.NODE); 
		System.out.println(rep.getNodeName());
		Node nam = (Node) xPath.compile("name").evaluate(rep, XPathConstants.NODE);
		System.out.println(nam.getTextContent());
		Node proc = (Node) xPath.compile("proc").evaluate(rep, XPathConstants.NODE);
		System.out.println(proc.getTextContent());
		NodeList col =  (NodeList) xPath.compile("columns/column").evaluate(rep, XPathConstants.NODESET);
		children = col;
		for (int i=0; i < children.getLength(); i++)
		{
			Node child = children.item(i);
			System.out.println(child.getNodeName());
			Element e =(Element)child;
			System.out.println("	name: " + e.getAttribute("name"));
			System.out.println("	val:  " +child.getNodeValue());
			System.out.println("	text:  " +child.getTextContent());
		//	System.out.println("class  " + child.getClass().getName());
		}
*/
		System.out.println("class  ");
	}
}
